// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import axios from './http'
import Vant from './components/vant/index'
import wx from 'weixin-js-sdk'
import qs from 'qs'

import Config from './config/config'

// 引用normalize.css
import 'normalize.css'

import './assets/style/vant-css/lib/index.css'

Vue.config.productionTip = false
Vue.prototype.axios = axios
Vue.prototype.wx = wx

Vue.use(Vant)

Vue.prototype.SDKRegister = (that, webUrl, jsApiList=[], callback) => {
  // 接入微信JSSDK
  // 获取微信JSSDK配置
  var url = '/system/get_wechat_jssdk_signature/'
  // alert(webUrl)
  var params = {
    'url': webUrl
  }
  if (!jsApiList.length) {
    jsApiList = [
       "onMenuShareAppMessage",
       "onMenuShareTimeline",
       "onMenuShareQQ",
       "onMenuShareWeibo",
       "chooseImage",
       "previewImage",
       "uploadImage",
       "startRecord",
       "stopRecord",
       "onVoiceRecordEnd",
       "playVoice",
       "pauseVoice",
       "stopVoice",
       "onVoicePlayEnd",
       "uploadVoice",
       "chooseWXPay"
     ]
  }
  axios.post(url, qs.stringify(params)).then(res => {
    res = res.data
    wx.config({
      debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
      appId: Config.appId, // 必填，公众号的唯一标识
      timestamp: res.timestamp, // 必填，生成签名的时间戳
      nonceStr: res.nonceStr, // 必填，生成签名的随机串
      signature: res.signature, // 必填，签名，见附录1
      // jsApiList: res.jsApiList
      jsApiList: jsApiList
    })
  })
  wx.ready((res) => {
    // 如果需要定制ready回调方法
    if(callback){
      callback.call(that)
    }
  })
}

/* eslint-disable no-new */
new Vue({
  el: '#app',
  axios,
  router,
  store,
  template: '<App/>',
  components: { App }
})
